﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Problem4
{
	// Find the largest palindrome made from the product of two 3-digit numbers.
	class Problem0004
	{
		static void Main(string[] args)
		{
			int product;
			int highJ = 0;
			int highI = 0;
			int highSum = 0;
			int answer = 0;
			string test;

			for (int i = 999; i > 99; i--)
			{
				for (int j = 999; j > 99; j--)
				{
					product = i * j;
					test = product.ToString();
					if (test == ReverseString(test))
					{
						if ((i + j) > highSum)
						{
							highSum = i + j;
							highI = i;
							highJ = j;
							answer = product;
						}
					}
				}
			}
			Console.WriteLine(highI);
			Console.WriteLine(highJ);
			Console.WriteLine(answer);
			Console.Read();
				
		}

		private static string ReverseString(string input)
		{
			var inputArray = input.ToCharArray();
			var reversedValue = string.Empty;

			for (int i = input.Length-1; i >= 0; i--)
			{
				reversedValue += inputArray[i];
			}

			return reversedValue;
		}
	}
}
